<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh">
<head>
    <meta charset="utf-8"/>
    <%--<meta name="viewport" content="width=device-width, initial-scale=1.0" />--%>
    <title>山西省审计厅档案综合管理系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="${basePath}/css/webUpload/style.css" rel="stylesheet"/>
    <link href="${basePath}/css/webUpload/demo.css" rel="stylesheet"/>
    <link href="${basePath}/css/webUpload/webuploader.css" rel="stylesheet"/>
    <link href="${basePath}/js/webuploader-0.1.5/webuploader.css" rel="stylesheet"/>
    <jsp:include page="/inc/footer.jsp" flush="true"/>
    <jsp:include page="/zheng-admin-plugins/plugins/inc/head.jsp" flush="true"/>
    <script src="${basePath}/js/devPublic.js"></script>
    <script src="${basePath}/js/date.js"></script>
    <script src="${basePath}/js/webuploader-0.1.5/webuploader.min.js"></script>
    <jsp:include page="/WEB-INF/jsp/preArchive/fileUpload.jsp" flush="true"/>
</head>

<style>
    *{
        margin:0;
        padding:0
    }
    .tablestyle tr{
        /*width: 100%*/
    }
    .tablestyle td{
        font-size: 13px;
        height:47px;
        vertical-align: top;
    }
    .tablestyle .content {
        padding-left: 0;
        padding-right: 8px;
        width: 90px;
        text-align: right;
        padding-top: 5px !important;
    }
    .tablestyle .form-group {
        width: 120px;
    }
    .tablestyle select {
        width: 100%;
        height: 28px;
    }
    .tablestyle input {
        border: 1px solid #AAAAAA;
        border-radius: 3px;
        width: 100%;
        height: 28px;
        padding-left: 5px;
    }
    .content .panel {
        margin-bottom: 0;
    }
    #arcType,
    #arcDeadline,
    #secretLevel {
        border: 1px solid #aaa;
        border-radius: 3px;
    }
    .help-block {
        margin-top: 0px;
        /*margin-right: 0px;*/
        line-height: 13px;
        margin-bottom: 0px;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" >
<input type="hidden" id="volId" name="volId" value="" >
<input type="hidden" id="itemId" name="itemId" value="" >
<!-- Main content -->
<section class="content">
    <div class="panel panel-default">
        <div class="panel-heading">著录区—卷信息</div>
        <div class="panel-body" <%-- style="height: 260px"--%>>
            <form id="JudForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator" method="post">
                <table id="archiveJudTable" class="tablestyle">
                    <tr>
                        <td class="content">
                           案卷题名
                        </td>
                        <td class="form-group" colspan="5">
                            <input type="text" id='judTitle' name='volTitle' placeholder="必填项" value='' />
                        </td>
                        <td class="content">
                           案&nbsp;卷&nbsp;号
                        </td>
                        <td class="form-group">
                            <input type="text" id='arcNumber' name='volNo' onblur="arcNumberNumMakeAction()"  <%--placeholder="必填项"--%> value=''/>
                        </td>
                        <td class="content">
                            总&nbsp;卷&nbsp;数
                        </td>
                        <td class="form-group">
                            <input type="number" id='allJudNumber' name='volTotal'  placeholder="必填项" value=''/>
                        </td>
                        <td class="content">
                           全宗号
                        </td>
                        <td class="form-group">
                            <input type="text" id='allArcNumber' name='volFian'  value='' readonly/>
                        </td>
                    </tr>
                    <tr>
                        <td class="content">
                            案卷类型
                        </td>
                        <td class="form-group" >
                            <select id="arcType" type="text" name="volClass" style="width: 100%;">
                            </select>
                        </td>
                        <td class="content" style="width: 120px">
                            审计起止日期
                        </td>
                        <td  class="form-group" style="width: 150px">
                            <input type="text" id='auditDate' name='volAuditDate' placeholder="示例：201901-201904"/>
                        </td>
                        <td class="content">
                            保管期限
                        </td>
                        <td class="form-group">
                            <select id="arcDeadline" <%--class="secretLevel"--%> name="volStorageTime" >
                            </select>
                        </td>
                        <td class="content">
                            审计组长
                        </td>
                        <td class="form-group">
                            <input type="text" id='auditPersosn' name='volAuditLeader' value=''/>
                        </td>
                        <td class="content">
                            当前卷数
                        </td>
                        <td class="form-group">
                            <input type="number" id='presentJudNumber' name='volCurrent' placeholder="必填项" value=''/>
                        </td>
                        <td class="content">
                            密&nbsp;&nbsp;&nbsp;&nbsp;级
                        </td>
                        <td class="form-group" style="width: 100px;">
                            <select id="secretLevel" class="secretLevel" name="volSecret" >
                            </select>
                        </td>
                        <td class="content">保密年限</td>
                        <td class="form-group">
                            <input type="number" id='secretDateline' name='volStr3' value='' <%-- style="width:100px"--%>/>
                            &nbsp;<%--<span style="margin-top: 5px">年</span>--%>
                        </td>

                    </tr>
                    <tr>
                        <td class="content">
                            归档单位
                        </td>
                        <td class="form-group" style="width:300px;">
                            <select type="text" id='arcApartment' name='volArchiveUnit' placeholder="必填项" value='' style="width: 100%;"></select>
                        </td>
                        <td class="content" style="width: 120px">
                            卷内起止日期
                        </td>
                        <td class="form-group" style="width: 150px">
                            <input type="text" id='judStartDate' name='volInsideDate'   placeholder="示例：201901-201904"/>
                        </td>
                        <td class="content">
                            归档年度
                        </td>
                        <td class="form-group">
                            <%--<input name="volArchiveYear" type="text"  id='arcYear'  class="Wdate" onfocus="WdatePicker({dateFmt: 'yyyy'})">--%>
                            <input name="volArchiveYear" type="text"  id='arcYear'  placeholder="必填项" >
                        </td>
                        <td class="content">
                            页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数
                        </td>
                        <td class="form-group">
                            <input type="number" id='pageNumber' placeholder="必填项" name='volTotalPage'   value=''/>
                        </td>
                        <td class="content">
                            备&nbsp;&nbsp;&nbsp;&nbsp;注
                        </td>
                        <td colspan="5" class="form-group" >
                            <input type="text" id='judRemarks' name='volDesc'  value=''/>
                        </td>
                    </tr>
                    <tr>
                        <td class="content">
                            件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数
                        </td>
                        <td class="form-group">
                            <input type="number" id='volItemNumber' name='volItemNumber'   value=''/>
                        </td>
                        <td class="content">
                            载体类型
                        </td>
                        <td class="form-group" style="width: 300px;">
                            <select id="volCarrier" name="volCarrier" >
                                <option value="2">共存</option>
                                <option value="1">仅电子</option>
                                <option value="0">仅实体</option>
                            </select>
                        </td>
                        <td class="content">
                            是否公开
                        </td>
                        <td class="form-group" style="width: 300px;">
                            <select id="volPublicStatus" class="secretLevel" name="volPublicStatus" >
                                <option value="0">未公开</option>
                                <option value="1">公开</option>
                            </select>
                        </td>
                        <td colspan="5"  class="form-group"><span style="color: red">*变更此字段卷内件会跟随变更</span></td>
                    </tr>
                </table>
                <div style="float:right;">
                    <button type="button" id="nextJud" onclick="nextOrSavaJud(1)" class="btn blue">新增卷</button>
                    <button type="button" id="savaJud" onclick="nextOrSavaJud(2)" class="btn blue">保存</button>
                </div>
            </form>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">著录区—卷内件信息</div>
        <div class="panel-body">
            <form id="ItemForm" class="form-horizontal form-bordered form-row-strippe" data-toggle="validator" method="post">
                <table id="archiveItemTable" class="tablestyle">
                    <tr>
                        <td class="content">
                            序号
                        </td>
                        <td class="form-group">
                            <input type="number" id='itemNumber' name='itemNum' min="1"  placeholder="必填项" value='1' readonly/>
                        </td>
                        <td class="content">
                            题名
                        </td>
                        <td class="form-group" colspan="7">
                            <input type="text" id='itemTitle' name='itemTitle'  placeholder="必填项" value='' />
                        </td>
                        <td class="content">
                            责任者
                        </td>
                        <td class="form-group" style="width:200px">
                            <input type="text" id='dutyPerson' name='itemRespons'  value=''/>
                        </td>
                    </tr>
                    <tr>
                        <td class="content">
                            页次
                        </td>
                        <td class="form-group">
                            <input type="number" id='itemPageNumber' name='itemPage' onblur="itemPageNumMakeAction()"  placeholder="必填项" value=''/>
                        </td>
                        <td class="content">
                            文号
                        </td>
                        <td class="form-group" style="width:300px">
                            <input type="text" id='itemFileNumber' name='itemName' value=''/>
                        </td>
                        <td class="content">
                            单元号
                        </td>
                        <td class="form-group">
                            <input type="text" id='partNumber' name='itemTemporary'  value=''/>
                        </td>
                        <td class="content">
                            发文日期
                        </td>
                        <td class="form-group" style="width:110px">
                            <input type="text" id='itemStartDate' name='itemCreateTime'   placeholder="示例：20190101"/>
                        </td>
                        <td class="content">
                            密&nbsp;&nbsp;&nbsp;&nbsp;级
                        </td>
                        <td class="form-group" style="width: 80px;margin-left: 0px">
                            <select id="itemSecretLevel" class="secretLevel" name="itemSecret" >
                            </select>
                        </td>
                        <td class="content">保密年限</td>
                        <td class="form-group">
                            <input type="number" id='itemSecretDateline' name='itemStr6' value='' style="width: 100%;float: left"/>
                            &nbsp;<%--<span  style="font-size: 15px;">年</span>--%>
                        </td>

                    </tr>
                    <tr id="itemPublic">
                        <td class="content">
                            是否公开
                        </td>
                        <td class="form-group" style="width: 300px;">
                            <select id="itemStr5" class="secretLevel" name="itemStr5" >
                                <option value="0">未公开</option>
                                <option value="1">公开</option>
                            </select>
                        </td>
                    </tr>
                </table>
                <div style="float: right">
                    <button type="button" id="nextItem" onclick="saveItemAction(1)" class="btn blue">新增件</button>
                    <button type="button" id="saveItem" onclick="saveItemAction(2)" class="btn blue">保存</button>
                </div>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">卷内件目录
        </div>
        <div class="table-left">
            <table id="table">
            </table>
        </div>
    </div>
    <!-- /.rowTable -->
</section>
<script src="${basePath}/zheng-admin-plugins/plugins/My97DatePicker/WdatePicker.js"></script>
<jsp:include page="/inc/operationTips.jsp" flush="true"/>
<jsp:include page="/WEB-INF/jsp/preArchive/viewOriginal.jsp" flush="true"/>
<script>
    var $table = $('#table');

    //记录从那个页面进入到著录页面，如果为undefined则表示直接从导航栏进入或不需要记录从那个页面进入。
    var positionPage="${position}";
    $(function (){
        bootstrapValidatorVol();
        bootstrapValidatorItem();
        initSelectarcApartment();
        findAllStorageTime();
        findAllJudType();
        findAllsecretLevelSin();
        loadAllArcNumberAction();
        /*var url = window.location.href;
        var volIdFromDetils = url.split("volIdToDetils=")[1];*/
        //著录阶段不开启该选项，默认未公开
        /*$("#volPublic").hide();
        $("#itemPublic").hide();*/

        var volIdFromDetils =${volIdToDetils};
        if(typeof volIdFromDetils == "undefined" || volIdFromDetils == null || volIdFromDetils == ""){
            return;
        }else{
            //编辑阶段开启该选项
            /*$("#volPublic").show();
            $("#itemPublic").show();*/
            $('#volId').val(volIdFromDetils);
            showJudMessage(volIdFromDetils);
            showItemMessage(volIdFromDetils);
            var urla = '${basePath}/pcwindow/findItemList?volId='+volIdFromDetils;
            loadItemTable(urla);
        }


    });

    /**
     * 件的表单验证
     * wr
     */
    function bootstrapValidatorItem(){
        $("#ItemForm").bootstrapValidator({
            live: 'submitted',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
            //submitButtons: '#saveItem,#nextItem',//指定提交按钮，如果验证失败则变成disabled
            message: '通用的验证失败消息',//好像从来没出现过
            feedbackIcons: {//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                itemTitle: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        }
                    }
                },
                itemPage:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                },
                itemStr6:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                },
                itemCreateTime:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^\d{8}$/,
                            message: '请输入正确日期'
                        }
                    }
                }
            }
        });
    }
    //件的form表单保存时刷新表单验证
    function refreshBootstrapValidatorItem(){
        //$("#ItemForm")[0].reset();
        $("#ItemForm").data('bootstrapValidator').resetForm();
        //$table.bootstrapTable('refresh');
    }

    /**
     * 卷的表单验证
     * wr
     */
    function bootstrapValidatorVol(){
        $("#JudForm").bootstrapValidator({
            live: 'submitted',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
            excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
            //submitButtons: '#savaJud,#nextJud',//指定提交按钮，如果验证失败则变成disabled
            message: '通用的验证失败消息',//好像从来没出现过
            feedbackIcons: {//根据验证结果显示的各种图标
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                volNo: {
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^\d{4}$/,
                            message: '请输入4位案卷号'
                        }
                    }
                },
                volTotalPage:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                },
                volTotal:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        },
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                },
                volCurrent:{
                    validators: {
                        callback: {
                            message: '≤总卷数且大于0,必填项',
                            callback: function (value, validator, $field) {
                                var otherbox = validator.getFieldElements('volTotal').val();//获得另一个的值
                                if ((parseInt(0) < parseInt(value))&& value.length!=0&&(parseInt(value) <= parseInt(otherbox))) {
                                    return true;
                                } else {
                                    return false;
                                }
                            }
                        }
                    }
                },
                volStorageTime:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        }
                    }
                },
                volTitle:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        }
                    }
                },
                volArchiveYear:{
                    validators: {
                        callback: {
                            message: '≥1900,必填项',
                            callback:function(value, validator, $field){
                                //callbackEdit(value);
                                var reg = /^\d{4}$/;
                                var now = new Date();
                                var year = now.getFullYear(); //获取当前年份
                                if(value.length!=0 && reg.test(value) && parseInt(value) <= parseInt(year) && parseInt(1900) <= parseInt(value)){
                                    return true;
                                }else {
                                    return false;
                                }
                            }
                        }
                    }
                },
                volArchiveUnit:{
                    validators: {
                        notEmpty: {//检测非空,radio也可用
                            message: '必填项'
                        }
                    }
                },
                volItemNumber:{
                    validators: {
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                },
                volStr3:{
                    validators: {
                        regexp: {
                            regexp: /^[1-9]\d*$/,
                            message: '请输入大于或等于1的值'
                        }
                    }
                }
            }
        });
    }
    //卷的form表单保存时刷新表单验证
    function refreshBootstrapValidator(){
        //$("#JudForm")[0].reset();
        $("#JudForm").data('bootstrapValidator').resetForm();
        //$table.bootstrapTable('refresh');


    }


    function loadItemTable(urla){
        $table.bootstrapTable({
            url:urla,
            striped: true,
            minimumCountColumns: 2,
            clickToSelect: true,//是否启用点击选中行
            singleSelect : true,
            detailView: false,
            detailFormatter: 'detailFormatter',
            pagination: false,
            pageList: [50, 100],
            smartDisplay:false,
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            escape: true,
            searchOnEnterKey: true,
            maintainSelected: true,
            columns: [
                {field: 'ck', checkbox: true},
                {field: 'itemNum', title: '序号',align: 'center'},
                {field: 'itemPage', title: '页次',align: 'center'},
                {field: 'itemTemporary', title: '单元号' ,align: 'center'},
                {field: 'itemTitle', title: '题名' ,align: 'center'},
                {field: 'itemCreateTime', title: '发文日期',align: 'center'},
                {field: 'itemName', title: '文号',align: 'center'},
                {field: 'itemRespons', title: '责任者' ,align: 'center'},
                {field: 'itemSecret', title: '密级',formatter: 'secretLevelFormatter'},
                {field: 'itemIsPdf',title: '挂接状态', formatter: 'statusFormatter'},
                {field: 'action', title: '操作',align: 'center', formatter: 'itemCreateActionFormatter', events: 'actionEvents', clickToSelect: false}
            ]
        });
        $("#table").on("check.bs.table", function () {         //点击radio触发事件
            var data = $("#table").bootstrapTable('getSelections');
            var  itemId = data[0].itemId
            $("#itemId").val(itemId);
            changeItemMeaasge(itemId);
        });
    }
    //格式化保管期限
    function storageTimeSinFormatter(value, row, index){
        return storageTime[value];
    }
    //格式化密级
    function secretLevelFormatter(value, row, index){
        return secretLevel[value];
    }
    //格式化归档单位
    function orgIdConversionNameFormatter(value, row, index){
        return orgList[value];
    }


    /**
     *	件操作按钮
     */
    function itemCreateActionFormatter(value, row, index) {
        if(typeof positionPage == "storage" || positionPage=="storage"){
            if(row.itemStr3 == 0){
                return '<a style="color:#01579b;" href="javascript:void(0)" onclick="singleMount(' + row.itemId +')"  >挂接原文</a>';
            }else {
                return '<a style="color:#01579b;" href="javascript:void(0)" onclick="detailAction(' + row.itemId + ')" >查看原文</a>&nbsp;&nbsp;&nbsp;' +
                    '<a style="color:#01579b;" href="javascript:void(0)" onclick="singleMount(' + row.itemId +')"  >挂接原文</a>';

            }
        }else{
            if(row.itemStr3 == 0){
                return '<a style="color:#01579b;" href="javascript:void(0)" onclick="singleMount(' + row.itemId +')"  >挂接原文</a>&nbsp;&nbsp;&nbsp;' +
                    '<a style="color:#01579b;" href="javascript:void(0)"  onclick="deleteJudItem('+row.itemId+',0)" >删除</a>';
            }else {
                return '<a style="color:#01579b;" href="javascript:void(0)" onclick="detailAction(' + row.itemId + ')" >查看原文</a>&nbsp;&nbsp;&nbsp;' +
                    '<a style="color:#01579b;" href="javascript:void(0)" onclick="singleMount(' + row.itemId +')"  >挂接原文</a>&nbsp;&nbsp;&nbsp;' +
                    '<a style="color:#01579b;" href="javascript:void(0)"  onclick="deleteJudItem('+row.itemId+',1)" >删除</a>';
            }
        }
    }
    // 挂接状态
    function statusFormatter(value, row, index) {
        if (row.itemStr3  == 0) {
            return '<span class="label label-info">未挂接</span>';
        }else if (row.itemStr3  == 1) {
            return '<span class="label label-success">已挂接</span>';
        }else {
            return '<span class="label label-primary">挂接失败</span>';
        }
    }
    /**
     * 删除件方法
     */
    function deleteJudItem(itemId,type){
        Ewin.confirm({message: '确认要删除吗？'}).on(function (e) {
            if (!e) {
                return;
            }else{
                var volId =$("#volId").val();
                $.ajax({
                    url:"${pageContext.request.contextPath }/pcwindow/deleteArcItem",
                    data:{
                        itemId:itemId,
                        type:type
                    },
                    type:"post",
                    dataType:"json",
                    success:function(result){
                        if(result.status != 200){
                            confirmEvent('删除失败，请您稍后再试!');
                        }else{
                            //重置table
                            $('#table').bootstrapTable('destroy');
                            var urla = '${basePath}/pcwindow/findItemList?volId='+volId;
                            loadItemTable(urla);
                        }
                    },
                    error: function() {
                        confirmEvent('系统开小差了，请稍后再试!');
                    }
                })
            }
        });
    }

    /**
     * 跳转原文页面
     */
    function detailAction(id){
        if(id !="" && id !=null){
            $.ajax({
                type: "post",
                url: "${basePath}/pcwindow/item/viewItemOriginal",
                data: { id: id },
                success: function (data) {
                    if (data != "failure") {
                        $('#openPdfModel').modal({
                            keyboard: true
                        });
                        var url=data;
                        var str = url.substr(url.length-4,url.length-1);
                        if(str==".jpg" || str==".png"){
                            var htmlImg = '<img src="'+url+'" style=" width:100%;height: 100%;" alt="预览">';
                            $("#pdfDialog").eq(0).append(htmlImg);
                        }else{
                            var options={
                                pdfOpenParams: {
                                    pagemode: "thumbs",
                                    navpanes: '0',
                                    /*toolbar: '0',*/ //去掉工具栏,打印,下载等,,,,
                                    statusbar: '0',
                                    view: 'FitV'
                                }};
                            var myPDF = PDFObject.embed(data, "#pdfDialog", options);
                        }
                    }else {
                        confirmEvent('获取原文失败!');
                    }
                },
                error: function () {
                    confirmEvent('加载错误,请联系管理员!');
                }
            })
        }else{
            confirmEvent('请选择数据!');
        }
    }

    function changeItemMeaasge(item) {
        $.ajax({
            type: 'POST',
            url: '${basePath}/pcwindow/showItemMessagesByItemId',
            dataType:"json",
            data:{
                itemId:item,
            },
            async:false,
            success: function(data){
                if (data.length != 0) {
                    $("#itemNumber").val(data.itemNum);//序号
                    $("#itemPageNumber").val(data.itemPage);//页次
                    $("#partNumber").val(data.itemTemporary);//单元号
                    $("#itemStartDate").val(data.itemCreateTime);//发文日期
                    $("#itemTitle").val(data.itemTitle);//题名
                    $("#itemFileNumber").val(data.itemName);//文号
                    $("#dutyPerson").val(data.itemRespons);//责任者
                    $("#itemSecretLevel").val(data.itemSecret);//密级
                    $("#itemSecretDateline").val(data.itemStr6);//保密期限
                    $("#itemStr5").val(data.itemStr5);//保密期限
                }else {
                    confirmEvent('查询失败，请您稍后再试!');
                }
            }
        });
    }
    function showJudMessage(volId) {
        $.ajax({
            type: 'POST',
            url: '${basePath}/pcwindow/findJudMessageByVolId',
            dataType:"json",
            data:{
                volId:volId,
            },
            async:false,
            success: function(data){
                if (data.length != 0) {
                    $("#arcType").val(data.volClass);//案卷类型
                    $("#arcDeadline").val(data.volStorageTime);//保存期限
                    $("#arcNumber").val(data.volNo);//档号
                    $("#allArcNumber").val(data.volFian);//全宗号
                    $("#judTitle").val(data.volTitle);//案卷题名
                    $("#arcYear").val(data.volArchiveYear);//归档年度
                    $("#arcApartment").val(data.volArchiveUnit);//归档单位
                    $("#auditPersosn").val(data.volAuditLeader);//审计组长
                    $("#auditDate").val(data.volAuditDate);//审计起止日期
                    $("#judStartDate").val(data.volInsideDate);//卷内起止日期
                    $("#allJudNumber").val(data.volTotal);//总卷数
                    $("#secretLevel").val(data.volSecret);//密级
                    $("#secretDateline").val(data.volStr3);//保密期限
                    //$("#secretDateline").val(data.volStr3);//保密期限
                    $("#presentJudNumber").val(data.volCurrent);//当前卷数
                    $("#pageNumber").val(data.volTotalPage);//页数
                    $("#judRemarks").val(data.volDesc);//备注
                    $("#volItemNumber").val(data.volItemNumber);//件数
                    $("#volPublicStatus").val(data.volPublicStatus);//是否公开
                    $("#volCarrier").val(data.volCarrier);//是否公开
                    /* $("#itemNum").attr("readonly","readonly");*/
                }else {
                    confirmEvent('查询失败，请您稍后再试!');
                }
            }
        });
    }
    function showItemMessage(volId) {
        $.ajax({
            type: 'POST',
            url: '${basePath}/pcwindow/showItemMessages',
            dataType:"json",
            data:{
                volId:volId
            },
            async:false,
            success: function(data){
                if (data.length != 0) {
                    var Item = data.rows;
                    $("#itemId").val(Item[0].itemId);//序号
                    $("#itemNumber").val(Item[0].itemNum);//序号
                    $("#itemPageNumber").val(Item[0].itemPage);//页次
                    $("#partNumber").val(Item[0].itemTemporary);//单元号
                    $("#itemStartDate").val(Item[0].itemCreateTime);//发文日期
                    $("#itemTitle").val(Item[0].itemTitle);//题名
                    $("#itemFileNumber").val(Item[0].itemName);//文号
                    $("#dutyPerson").val(Item[0].itemRespons);//责任者
                    $("#itemSecretLevel").val(Item[0].itemSecret);//密级
                    $("#itemSecretDateline").val(Item[0].itemStr6);//保密期限
                    $("#itemStr5").val(Item[0].itemStr5);//保密期限
                }else {
                    confirmEvent('查询失败，请您稍后再试!');
                }
            }
        });
    }

    //档案卷提交
    function nextOrSavaJud(rt){
        $("#JudForm").bootstrapValidator('validate');//提交验证
        if ($("#JudForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码

            var volId =$("#volId").val();
           var pageNumber=$("#pageNumber").val();//页数
            /* if(pageNumber == "" || arcApartment == undefined){
                alert("页数不能为空");
                return;
            }*/
            //校验页数
            $.ajax({
                type: "POST",
                url:"${pageContext.request.contextPath }/pcwindow/checkItemPageAndVolumePage",
                data:{
                    volId:volId,
                    pageNumber:pageNumber
                },
                type:"post",
                dataType:"json",
                async:false,
                success:function(result){
                    if(result.status != 200){
                        confirmEvent('卷的页数有误，需大于等于最大件的页次!');
                    }else{
                        if(rt == 1){

                            if(volId == ""){
                                confirmEvent('请先保存该条著录信息!');
                                return;
                            }else{
                                //清空表单信息，volId清空，复选框重置
                                //用户点击下一卷，清空本卷信息
                                //清空volId
                                $("#volId").val("");
                                //清空卷表单
                                $("#JudForm")[0].reset();
                                //清空件表单
                                $("#ItemForm")[0].reset();
                                //重置选项框
                                findAllJudType();
                                findAllsecretLevelSin();
                                findAllStorageTime();
                                loadAllArcNumberAction();
                                initSelectarcApartment();
                                $("arcDeadline").find("option:selected").attr("selected", false);
                                //重置table
                                $('#table').bootstrapTable('destroy');
                                var urla = '${basePath}/pcwindow/findItemList?volId='+volId;
                                loadItemTable(urla);
                                refreshBootstrapValidator();
                            }

                        }else{
                            //进行表单验证
                            var url ="${basePath}/pcwindow/insertJudMessage";
                            var arcType=$("#arcType").find(":selected").val();//案卷类型
                            var arcDeadline=$("#arcDeadline").find(":selected").val();//保管期限
                            /*if(arcDeadline == "" || arcDeadline == undefined){
                                alert("保管期限不能为空");
                                return;
                            }*/
                            var arcNumber=$("#arcNumber").val();//案卷号
                            var allArcNumber=$("#allArcNumber").val();//全宗号
                            var judTitle=$("#judTitle").val();//案卷题名
                            /*if(judTitle == "" || judTitle == undefined){
                                alert("案卷题名不能为空");
                                return;
                            }*/
                            var arcYear=$("#arcYear").val();//归档年度
                            /*if(arcYear == "" || arcYear == undefined){
                                alert("归档年度不能为空");
                                return;
                            }*/
                            var arcApartment=$("#arcApartment").val();//归档单位
                            /*if(arcApartment == "" || arcApartment == undefined){
                                alert("归档单位不能为空");
                                return;
                            }*/
                            var auditPersosn=$("#auditPersosn").val();//审计组长
                            var secretLevel = $("#secretLevel").val();//密级
                            var secretDateline = $("#secretDateline").val();//保密期限
                            /*if(pageNumber<1){
                                alert("页数不能小于1");
                                return;
                            }*/
                            var auditDate=$("#auditDate").val();//审计起止日期
                            var judStartDate=$("#judStartDate").val();//卷内起止日期
                            var allJudNumber=$("#allJudNumber").val();//总卷数
                            /*if(allJudNumber == "" || allJudNumber == undefined){
                                alert("总卷数不能为空");
                                return;
                            }*/
                            var presentJudNumber=$("#presentJudNumber").val();//当前卷数
                            /*if(presentJudNumber == "" || presentJudNumber == undefined){
                                alert("当前卷数不能为空");
                                return;
                            }*/
                            var judRemarks=$("#judRemarks").val();//备注
                            var volPublicStatus=$("#volPublicStatus").val();//是否公开
                            var volCarrier=$("#volCarrier").val();//载体类型
                            var volItemNumber=$("#volItemNumber").val();//件数
                            var data={
                                volId:volId,
                                arcType:arcType,
                                arcDeadline:arcDeadline,
                                arcNumber:arcNumber,
                                allArcNumber:allArcNumber,
                                judTitle:judTitle,
                                arcYear:arcYear,
                                arcApartment:arcApartment,
                                auditPersosn:auditPersosn,
                                secretLevel:secretLevel,
                                secretDateline:secretDateline,
                                pageNumber:pageNumber,
                                auditDate:auditDate,
                                judStartDate:judStartDate,
                                allJudNumber:allJudNumber,
                                presentJudNumber:presentJudNumber,
                                judRemarks:judRemarks,
                                volPublicStatus:volPublicStatus,
                                volCarrier:volCarrier,
                                volItemNumber:volItemNumber
                            }
                            $.ajax({
                                url:url,
                                data:data,
                                type:"post",
                                dataType:"json",
                                success:function(result){
                                    if(result.status != 200) {
                                        confirmEvent('保存卷著录信息失败，请稍后再试!');
                                    }else{
                                        $("#volId").val(result.msg);
                                        confirmEvent('保存卷著录信息成功!');
                                        //refreshBootstrapValidator();
                                    }
                                },
                                error: function() {
                                    confirmEvent('系统开小差了，请稍后再试!');
                                }
                            })
                        }
                    }
                }
            });
        }
    }
    function saveItemAction(rs) {
        var volId =$("#volId").val();
        var itemId =$("#itemId").val();
        if(volId == null || volId == ""){
            confirmEvent('请先保存该条卷著录信息!');
        }else {
            $("#ItemForm").bootstrapValidator('validate');//提交验证
            if ($("#ItemForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
                var pageNumber=$("#pageNumber").val();//页数
                var itemPageNumber=$("#itemPageNumber").val();//页次
                /*if(pageNumber == "" || pageNumber == undefined){
                    alert("卷页次不能为空");
                    return;
                }*/
                /*if(itemPageNumber == "" || itemPageNumber == undefined){
                    alert("卷内件页次不能为空");
                    return;
                }*/
                //校验页数
                $.ajax({
                    type: "POST",
                    url:"${pageContext.request.contextPath }/pcwindow/saveItemCheckItemPageAndVolumePage",
                    data:{
                        itemPageNumber:itemPageNumber,
                        volId:volId,
                        pageNumber:pageNumber
                    },
                    type:"post",
                    dataType:"json",
                    async:false,
                    success:function(result) {
                        if (result.status != 200) {
                            confirmEvent('页次有误，需小于等于卷的页数!');
                        } else {

                            //进行表单验证
                            var url ="${basePath}/pcwindow/insertItemMessage";
                            var partNumber=$("#partNumber").val();//单元号
                            var itemStartDate=$("#itemStartDate").val();//发文日期
                            var itemNumber=$("#itemNumber").val();//序号
                            /*if(itemStartDate == "" || itemStartDate == undefined){
                                alert("发文日期不能为空");
                                return;
                            }*/
                            var itemTitle=$("#itemTitle").val();//题名
                            /*if(itemTitle == "" || itemTitle == undefined){
                                alert("题名不能为空");
                                return;
                            }*/
                            var itemFileNumber=$("#itemFileNumber").val();//文号
                            var dutyPerson = $("#dutyPerson").val();//责任者
                            var itemSecretLevel = $("#itemSecretLevel").val();//密级
                            var itemSecretDateline = $("#itemSecretDateline").val();//密级
                            var itemStr5 = $("#itemStr5").val();//是否公开
                            var data1={
                                volId:volId,
                                itemId:itemId,
                                itemNumber:itemNumber,
                                itemPageNumber:itemPageNumber,
                                partNumber:partNumber,
                                itemStartDate:itemStartDate,
                                itemTitle:itemTitle,
                                itemFileNumber:itemFileNumber,
                                dutyPerson:dutyPerson,
                                itemSecretLevel:itemSecretLevel,
                                itemSecretDateline:itemSecretDateline,
                                itemStr5:itemStr5
                            };
                            $.ajax({
                                url:url,
                                data:data1,
                                type:"post",
                                dataType:"json",
                                success:function(result){
                                    if(result.status != 200){
                                        confirmEvent('保存件信息失败，请稍后再试!');
                                    }else{
                                        if(rs == 1){
                                            //下一条，清除itemId
                                            $("#itemId").val("");
                                            //清空表单
                                            $("#ItemForm")[0].reset();
                                            addItemNumber();
                                            refreshBootstrapValidatorItem();
                                        }else{
                                            //用户点击保存，清除itemId
                                            $("#itemId").val(result.msg);
                                            //refreshBootstrapValidatorItem();
                                            confirmEvent('保存件信息成功!');
                                        }
                                        $('#table').bootstrapTable('destroy');
                                        var urla = '${basePath}/pcwindow/findItemList?volId='+volId;
                                        loadItemTable(urla);
                                    }
                                },
                                error: function() {
                                    confirmEvent('系统开小差了，请稍后再试!');
                                }
                            })
                        }
                    }
                });

            }
        }
    }
    function addItemNumber () {
        var volId =$("#volId").val();
        $.ajax({
            type: "POST",
            url:"${pageContext.request.contextPath }/pcwindow/findMaxItemNumber",
            data:{
                volId:volId,
            },
            type:"post",
            dataType:"json",
            success:function(result){
                $("#itemNumber").val(result + 1);//序号
            }
        });
    }
    /**
     *	加载所有案卷类型
     */
    function findAllJudType(){
        $.ajax({
            type: "POST",
            url:"${pageContext.request.contextPath }/pcwindow/findAllJudType",
            dataType:"json",
            async:false,
            success: function(data){
                if (data.length != 0) {
                    initMaterialInput();
                    $('#arcType').select2({
                        placeholder: '请选择',
                        allowClear: true
                    });
                    var arcTypes = data.rows;
                    var str;
                    for(var i = 0;i < arcTypes.length ;i++){
                        var tyname=arcTypes[i].sortName;
                        var tyid=arcTypes[i].sortNum;
                        str += '<option value="'+ tyid +'">'+ tyid +'-'+ tyname +'</option>'
                    }
                    $('#arcType').html(str);
                }
            }
        });
    }

    /**
     *	加载所有保管期限
     */
    function findAllStorageTime(){
        $.ajax({
            type: "POST",
            url:"${pageContext.request.contextPath }/pcwindow/findAllStorageTime",
            dataType:"json",
            async:false,
            success: function(data){
                if (data.length != 0) {
                    var arcStorageTime = data.rows;
                    var str;
                    for(var i = 0;i < arcStorageTime.length ;i++){
                        var tyname=arcStorageTime[i].description;
                        var tyid=arcStorageTime[i].code;
                        str += '<option value="'+ tyid +'">'+ tyname +'</option>'
                    }
                    $('#arcDeadline').html(str);
                }
            }
        });
    }
    //单件挂接
    function singleMount(itemId){
        $("#uploadSubmit").attr("data-id",itemId);
        $("#uploadSubmit").attr("data-type",1);
        $("#uploadSubmit").attr("data-fileNum",1);
        $("#uploadSubmit").attr("data-tableId","table");
        // 加载addmodel
        $('#showUploadModal').modal({
            keyboard: true
        });
    }
    //加载案卷号，唯一
    function arcNumberNumMakeAction() {
        var volId =$("#volId").val();
        var arcNumber = $("#arcNumber").val();
        $.ajax({
            url:"${pageContext.request.contextPath }/pcwindow/findarcNumber",
            data:{
                volId:volId,
                arcNumber:arcNumber,
            },
            type:"post",
            dataType:"json",
            success:function(result){
                if(result.status != 200){
                    confirmEvent('该案卷号已存在，请您重新输入!');
                    return;
                }
            },
            error: function() {
                confirmEvent('系统开小差了，请稍后再试!');
            }
        })
    }
    
    //加载卷内件页次，唯一
    function itemPageNumMakeAction() {
        var volId =$("#volId").val();
        var itemId =$("#itemId").val();
        var itemPageNumber = $("#itemPageNumber").val();
        $.ajax({
            url:"${pageContext.request.contextPath }/pcwindow/findItemPage",
            data:{
                volId:volId,
                itemId:itemId,
                itemPageNumber:itemPageNumber,
            },
            type:"post",
            dataType:"json",
            success:function(result){
                if(result.status != 200){
                    confirmEvent('该页次已存在，请您重新输入!');
                }
            },
            error: function() {
                confirmEvent('系统开小差了，请稍后再试!');
            }
        })
    }
    //加载全宗号
    function loadAllArcNumberAction() {
        $.ajax({
            type: "POST",
            url:"${pageContext.request.contextPath }/manage/fonds/list",
            dataType:"json",
            async:false,
            success: function(data){
                if (data.length != 0) {
                    $("#allArcNumber").val(data[0].fondsNum);
                }
            }
        });
    }
    /**
     * 加载所有密级
     */
    function findAllsecretLevelSin(){
        $.ajax({
            type: "POST",
            url:BASE_PATH+"/pcwindow/findAllSecretLevel",
            dataType:"json",
            async:false,
            success: function(data){
                if (data.length != 0) {
                    var findAllsecretLevel = data.rows;
                    var str =  '<option value="">请选择</option>';
                    for(var i = 0;i < findAllsecretLevel.length ;i++){
                        var name=findAllsecretLevel[i].description;
                        var id=findAllsecretLevel[i].code;
                        str += '<option value="'+ id +'">'+ name +'</option>'
                    }
                    $('#itemSecretLevel').html(str);
                    $('#secretLevel').html(str);
                }
            }
        });
    }
    /**
     * 加载归档单位
     */
    function initSelectarcApartment() {
        $.ajax({
            type: "POST",
            url:BASE_PATH+"/pcwindow/findAllOrg",
            dataType:"json",
            async:false,
            success: function(data){
                if (data.length != 0) {
                    initMaterialInput();
                    $('#arcApartment').select2({
                        placeholder: '请选择',
                        allowClear: true
                    });
                }
                var str='';
                for(var i = 0;i < data.length ;i++){
                    var name=data[i].name;
                    var id=data[i].organizationId;
                    str += '<option value="'+ id +'">'+ name +'</option>'
                }
                $('#arcApartment').html(str);
            }
        });
    }
</script>
</body>
</html>

